package com.fulihui.systemcore.repository.impl;

import com.fulihui.systemcore.dal.dataobj.PhoneRegLocExample;
import com.fulihui.systemcore.dal.mapper.PhoneRegLocMapper;
import com.fulihui.systemcore.dto.PhoneRegLocDTO;
import com.fulihui.systemcore.repository.PhoneRegLocRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static com.fulihui.systemcore.biz.conv.PhoneRegLocConv.toDO;
import static com.fulihui.systemcore.biz.conv.PhoneRegLocConv.toMap;

/**
 * @author Willard.Hu on 2016/11/29 0029.
 */
@Repository
public class PhoneRegLocRepositoryImpl implements PhoneRegLocRepository {

    @Autowired
    PhoneRegLocMapper phoneRegLocMapper;

    @Override
    public Map<Integer, PhoneRegLocDTO> queryByPrefixs(List<Integer> prefixs) {
        if (CollectionUtils.isEmpty(prefixs)) {
            return Collections.emptyMap();
        }
        PhoneRegLocExample example = new PhoneRegLocExample();
        example.createCriteria().andPrefixIn(prefixs);
        return toMap(phoneRegLocMapper.selectByExample(example));
    }

    @Override
    public void create(PhoneRegLocDTO dto) {
        phoneRegLocMapper.insert(toDO(dto));
    }
}
